Hệ thống quản lý thanh toán POS nhà hàng

1 Imports System.Data.OleDb
2
3 Public Class frmLogs
4
5     Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
6         Me.Close()
7     End Sub
8     Sub fillCombo()
9         Try
10             Dim CN As New OleDbConnection(cs)
11             CN.Open()
12             adp = New OleDbDataAdapter()
13             adp.SelectCommand = New OleDbCommand(
"SELECT distinct RTRIM(UserID) FROM Registration", CN)
14             ds = New DataSet(
"ds")
15             adp.Fill(ds)
16             Dim dtable As DataTable = ds.Tables(
0)
17             cmbUserID.Items.Clear()
18             For Each drow As DataRow In dtable.Rows
19                 cmbUserID.Items.Add(drow(
0).ToString())
20             Next
21
22         Catch ex As Exception
23             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
24         End Try
25     End Sub
26
27     Private Sub cmbUserID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbUserID.SelectedIndexChanged
28         Try
29             con = New OleDbConnection(cs)
30             con.Open()
31             cmd = New OleDbCommand(
"SELECT RTRIM(UserID),[Date],RTRIM(Operation) from Logs where UserID='" & cmbUserID.Text & "' order by date", con)
32             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
33             dgw.Rows.Clear()
34             While (rdr.Read() = True)
35                 dgw.Rows.Add(rdr(
0), rdr(1), rdr(2))
36             End While
37             con.Close()
38         Catch ex As Exception
39             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
40         End Try
41     End Sub
42     Private Sub GetData()
43         Try
44             con = New OleDbConnection(cs)
45             con.Open()
46             cmd = New OleDbCommand(
"SELECT RTRIM(UserID),[Date],RTRIM(Operation) from Logs order by Date", con)
47             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
48             dgw.Rows.Clear()
49             While (rdr.Read() = True)
50                 dgw.Rows.Add(rdr(
0), rdr(1), rdr(2))
51             End While
52             con.Close()
53         Catch ex As Exception
54             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
55         End Try
56     End Sub
57     Private Sub frmLogs_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
58         fillCombo()
59         GetData()
60     End Sub
61     Sub Reset()
62         cmbUserID.SelectedIndex = -
1
63         dtpDateFrom.Text = Today
64         dtpDateTo.Text = Now
65         GetData()
66         fillCombo()
67     End Sub
68     Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
69         Reset()
70     End Sub
71
72     Private Sub btnGetData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetData.Click
73         Try
74             con = New OleDbConnection(cs)
75             con.Open()
76             cmd = New OleDbCommand(
"SELECT RTRIM(UserID),[Date],RTRIM(Operation) from logs where [Date] between #" & dtpDateFrom.Value.Date & "# and #" & dtpDateTo.Value & "# order by Date", con)
77             rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
78             dgw.Rows.Clear()
79             While (rdr.Read() = True)
80                 dgw.Rows.Add(rdr(
0), rdr(1), rdr(2))
81             End While
82             con.Close()
83         Catch ex As Exception
84             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
85         End Try
86     End Sub
87
88     Private Sub btnClose_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
89         Me.Close()
90     End Sub
91
92     Private Sub btnExportExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportExcel.Click
93         ExportExcel(dgw)
94     End Sub
95
96     Private Sub dgw_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgw.RowPostPaint
97         Dim strRowNumber As String = (e.RowIndex +
1).ToString()
98         Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
99         If dgw.RowHeadersWidth < Convert.ToInt32((size.Width +
20)) Then
100             dgw.RowHeadersWidth = Convert.ToInt32((size.Width +
20))
101         End If
102         Dim b As Brush = SystemBrushes.ControlText
103         e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X +
15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
104
105     End Sub
106     Public Sub DeleteRecord()
107         Try
108             Dim RowsAffected As Integer =
0
109             con = New OleDbConnection(cs)
110             con.Open()
111             Dim ct As String =
"delete from logs"
112             cmd = New OleDbCommand(ct)
113             cmd.Connection = con
114             RowsAffected = cmd.ExecuteNonQuery()
115             If con.State = ConnectionState.Open Then
116                 con.Close()
117             End If
118             If RowsAffected >
0 Then
119                 Dim st As String =
"deleted the all logs till date '" & Now.ToString("dd/MM/yyyy hh:mm:ss tt") & "'"
120                 LogFunc(lblUser.Text, st)
121                 MessageBox.Show(
"Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information)
122                 Reset()
123                 Reset()
124                 GetData()
125             Else
126                 MessageBox.Show(
"No record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information)
127                 Reset()
128             End If
129             con.Close()
130         Catch ex As Exception
131             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
132         End Try
133     End Sub
134     Private Sub btnDeleteAllLogs_Click(sender As System.Object, e As System.EventArgs) Handles btnDeleteAllLogs.Click
135         Try
136             If MessageBox.Show(
"Do you really want to delete all logs?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
137                 DeleteRecord()
138             End If
139         Catch ex As Exception
140             MessageBox.Show(ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
141         End Try
142     End Sub
143
144   
145 End Class


Gõ tìm kiếm nhanh...